
********FIRST FIVE COLUMNS********
est clear

use "$jfqa_rep/20_Stock_Setup.dta", clear

qui{
drop if missing(convexity_split)
drop if missing(futret)

drop if year<1963
drop if year==1963 & month<6

drop if year>2022
drop if year==2022 & month==12

*convexity split rank
gen convex_five=.
sort monthyear convexity_split
by monthyear: replace convex_five=1 if _n<_N/5
by monthyear: replace convex_five=2 if _n>=_N/5 & _n<_N/5*2
by monthyear: replace convex_five=3 if _n>=_N/5*2 & _n<_N/5*3 
by monthyear: replace convex_five=4 if _n>=_N/5*3 & _n<_N/5*4
by monthyear: replace convex_five=5 if _n>=_N/5*4

replace futret=futret*100
replace futexcess=futexcess*100

egen ew_raw=mean(futret), by(monthyear convex_five)
egen ew_excess=mean(futexcess), by(monthyear convex_five)

*consolidate to one observation per month
sort convex_five monthyear 
collapse ew_raw ew_excess, by(convex_five monthyear)

tsset convex_five monthyear  

forval i=1/5 {
	eststo: newey ew_raw if convex_five ==`i', lag(6)
}

egen std_ew=sd(ew_excess), by(convex_five)

egen mean_ret_ew=mean(ew_excess), by(convex_five)

gen sharpe_ew=mean_ret_ew/std_ew 

keep convex_five std_ew mean_ret_ew sharpe_ew

duplicates drop
}

tab convex_five, sum(sharpe_ew)


********LAST COLUMN********
use "$jfqa_rep/20_Stock_Setup.dta", clear

qui{
drop if missing(convexity_split)
drop if missing(futret)

drop if year<1963
drop if year==1963 & month<6

drop if year>2022
drop if year==2022 & month==12

*convexity split rank
gen convex_five=.
sort monthyear convexity_split
by monthyear: replace convex_five=1 if _n<_N/5
by monthyear: replace convex_five=2 if _n>=_N/5 & _n<_N/5*2
by monthyear: replace convex_five=3 if _n>=_N/5*2 & _n<_N/5*3 
by monthyear: replace convex_five=4 if _n>=_N/5*3 & _n<_N/5*4
by monthyear: replace convex_five=5 if _n>=_N/5*4


replace futret=futret*100
replace futexcess=futexcess*100

egen ew_raw=mean(futret), by(monthyear convex_five)
egen ew_excess=mean(futexcess), by(monthyear convex_five)

*consolidate to one observation per month
sort convex_five monthyear 
collapse ew_raw ew_excess, by(convex_five monthyear)

tsset convex_five monthyear  

sort  convex_five monthyear

keep if convex_five==1 | convex_five==5

sort monthyear convex_five

gen ew_excess_dif=ew_excess-ew_excess[_n+1] if convex_five==1

keep if convex_five==1

sort  convex_five monthyear


eststo: newey ew_excess_dif , lag(6)

egen std_ew=sd(ew_excess_dif)

egen mean_ret_ew=mean(ew_excess_dif) 

gen sharpe_ew=mean_ret_ew/std_ew 
}

tab convex_five, sum(sharpe_ew)

esttab using "$jfqa_rep/Table_IA4A.csv", nostar replace b(2)

